package com.youlai.system.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.youlai.system.common.result.PageResult;
import com.youlai.system.common.result.Result;
import com.youlai.system.pojo.form.StudentForm;
import com.youlai.system.pojo.query.StudentPageQuery;
import com.youlai.system.pojo.vo.StudentPageVO;
import com.youlai.system.service.ExampleStudentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.web.bind.annotation.*;

@Tag(name = "08.学生接口")
@RestController
@RequestMapping("/api/students")
@RequiredArgsConstructor
public class StudentController {

    private final ExampleStudentService exampleStudentService;

    @Operation(summary = "学生信息分页列表", security = {@SecurityRequirement(name = "Authorization")})
    @GetMapping("/page")
    public PageResult<StudentPageVO> getStudentPage(
            @ParameterObject StudentPageQuery queryParams
    ){

        Page<StudentPageVO> result = exampleStudentService.getStudentPage(queryParams);

        return PageResult.success(result);


    }
    @Operation(summary = "学生信息表单数据", security = {@SecurityRequirement(name = "Authorization")})
    @GetMapping("/{id}/form")
    public Result<StudentForm> getStudentForm(
           @Parameter(description = "学生信息ID") @PathVariable Long id
    ){
        StudentForm studentForm = exampleStudentService.getStudentForm(id);

        return Result.success(studentForm);

    }

    @Operation(summary = "新增学生", security = {@SecurityRequirement(name = "Authorization")})
    @PostMapping
    public Result saveStudent(
            @RequestBody StudentForm studentForm
    ){
        boolean result = exampleStudentService.saveStudent(studentForm);
        return Result.judge(result);
    }

    @Operation(summary = "修改学生", security = {@SecurityRequirement(name = "Authorization")})
    @PutMapping("/{id}")
    public Result updateStudent(
            @PathVariable Long id,
            @RequestBody StudentForm studentForm

    ){
        boolean result = exampleStudentService.updateStudent(id, studentForm);

        return Result.judge(result);
    }

    @Operation(summary = "删除学生", security = {@SecurityRequirement(name = "Authorization")})
    @DeleteMapping("/{ids}")
    public Result deleteStudent(
            @Parameter(description ="学生信息ID，多个以英文逗号(,)拼接") @PathVariable String ids
    ){
        boolean result = exampleStudentService.deleteStudent(ids);

        return Result.judge(result);
    }



}
